<?php  
  
if(isset($_FILES['files'])){  
    $res =  upload_multiple_file($_FILES['files'],"/home/halo/learning/upload");  
    echo $res;  
    }  
  
  
function upload_multiple_file($file,$file_dir="/home/halo/learning/upload") {  
  
    $overwrite=0;  
    $allowed_file_type= array("pdf","ppt","pptx","xls","xlxs","doc","docx","jpg", "jpeg", "png", "gif");  
    $max_file_size = 2097152;  
  
     foreach($_FILES['files']['name'] as $fkey=> $fname){  
        
         $ext = pathinfo($fname, PATHINFO_EXTENSION);  
           if (!in_array($ext, $allowed_file_type)) {  
             
               return "unsupported file format";  
                break;  
           }  
        
       
     }  
  
    foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){  
          
                  
        $file_name = $_FILES['files']['name'][$key];  
          
          
        $file_size =$_FILES['files']['size'][$key];  
          
          
        $file_tmp_name =$_FILES['files']['tmp_name'][$key];  
          
          
        $file_type=$_FILES['files']['type'][$key];  
  
          
        if($file_size >0) {  
            if($file_size > $max_file_size){  
              
                $fsize=$max_file_size/1048576;  
                return  'File size must be less than '.$fsize.' MB';  
                break;  
            
            }  
        }  
          
       
        if(is_dir($file_dir)==false){  
              
              $status =  mkdir("$file_dir", 0700);    
                 
               if($status < 1){  
                       
                     return "unable to create  diractory $file_dir ";  
                       
                }                
              
        }  
              
        if(is_dir($file_dir)){  
              
            if($overwrite < 1){  
                
                move_uploaded_file($file_tmp_name,"$file_dir/".$file_name);  
               
            }  
               
        }  
             
        //  $file_upload_query="INSERT into user_uploads (`u_id`,`file_name`,`file_type`) VALUES('$user_id','$file_name','$file_size','$file_type'); ";  
        //mysql_query($file_upload_query);        
          
      
   }  
      
        return "Success";  
      
}  
  
?>  
